package com.lyrcsoft.rxjava1x.operators.filter;

import com.lyrcsoft.rxjava1x.dao.DataUtils;
import com.lyrcsoft.rxjava1x.entity.Community;
import lombok.extern.slf4j.Slf4j;
import rx.Observable;
import rx.functions.Action1;
import rx.functions.Func1;

/**
 * @author fujc2dev@126.com
 * @date 2024-11-21
 */
@Slf4j
public class filter {
    public static void main(String[] args) {
        log.debug("----------- rxJavafilter ---------");
        /**
         * filter(Func1)用来过滤观测序列中我们不想要的值，只返回满足条件的值
         */
        Observable.from(DataUtils.getCommunityList())
                .filter(new Func1<Community, Boolean>() {
                    @Override
                    public Boolean call(Community community) {
                        // 过滤
                        return community.getHouses().size() >= 1;
                    }
                })
                .subscribe(new Action1<Community>() {
                    @Override
                    public void call(Community community) {
                        System.out.println(community.getName());
                    }
                });
    }
}
